#cmake file for project opencl
#author:guyadong
#created:2016/01/09
cmake_minimum_required( VERSION 2.6 )

####定义 OpenCL 不同版本的头文件位置,
##如:1.2版本定义为变量INCLUDE_OPENCL1_2
foreach ( version 1.0 1.1 1.2 2.0 2.1 )
	set ( version_dir "${CMAKE_CURRENT_LIST_DIR}/include/${version}" )
	if( NOT IS_DIRECTORY "${version_dir}" )
		MESSAGE(FATAL_ERROR "not found directory:${version_dir}") 
	endif()
	string(REPLACE "." "_" suffix ${version} )
	set ( include_dir "${CMAKE_CURRENT_LIST_DIR}/include/${version}")
	set(INCLUDE_OPENCL${suffix} "${include_dir}" CACHE INTERNAL "Value Computed by CMake" )
	message(STATUS "INCLUDE_OPENCL${suffix}=${INCLUDE_OPENCL${suffix}}" )
endforeach()

##根据 OPENCL_VERSION_REQUIRED 指定的OpenCL版本号设置全局变量INCLUDE_OPENCL_REQUIRED，定义OpenCL文件位置
##所有其他项目可以通过读取INCLUDE_OPENCL_REQUIRED全局变量来获取OpenCL头文件的位置
if( OPENCL_VERSION_REQUIRED )
	string(REPLACE "." "_" suffix ${OPENCL_VERSION_REQUIRED} )
	if( !INCLUDE_OPENCL${suffix})
		MESSAGE(FATAL_ERROR "not defined global property 'INCLUDE_OPENCL${suffix}'" )
	endif()
	set(INCLUDE_OPENCL_REQUIRED "${INCLUDE_OPENCL${suffix}}" CACHE INTERNAL "Value Computed by CMake" )
	message(STATUS "INCLUDE_OPENCL_REQUIRED=${INCLUDE_OPENCL_REQUIRED}" )
endif()

## 查找OpenCL SDK
find_package(OpenCL)
if(OpenCL_FOUND)
message(STATUS "OpenCL_INCLUDE_DIRS=${OpenCL_INCLUDE_DIRS}")
message(STATUS "OpenCL_LIBRARY=${OpenCL_LIBRARY}")
message(STATUS "OpenCL_VERSION_STRING=${OpenCL_VERSION_STRING}")
else()
message(FATAL_ERROR   "OpenCL NOT FOUND")
endif()
#set( SUBDIRECTORIES OpenCL-ICD-Loader)
#foreach( subdir ${SUBDIRECTORIES} )
#	if( IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${subdir}" )
#		MESSAGE( STATUS "Found sub project ${subdir}, adding it" )
#		add_subdirectory( ${subdir} )
#	endif()
#endforeach()
